package com.huangfuyi.home.dao;

import com.huangfuyi.home.entity.ModuleEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface ModuleDao {

    @Insert("insert into e_module (" +
            "id, " +
            "name, " +
            "label, " +
            "src, " +
            "icon, " +
            "description, " +
            "position" +
            ") values (" +
            "#{id}" +
            "#{name}" +
            "#{label}" +
            "#{src}" +
            "#{icon}" +
            "#{description}" +
            "#{position}" +
            ")")
    int add(ModuleEntity module);

    @Delete("delete from e_module where id = #{id}")
    int deleteById(String id);

    @Update("<script>" +
            "update e_module " +
            "<set>" +
            "<if test=\"name != null and name != ''\">name = #{name}, </if>" +
            "<if test=\"label != null and label != ''\">label = #{label}, </if>" +
            "<if test=\"src != null and src != ''\">src = #{src}, </if>" +
            "<if test=\"icon != null and icon != ''\">icon = #{icon}, </if>" +
            "<if test=\"description != null and description != ''\">description = #{description}, </if>" +
            "<if test=\"position != null and position != ''\">position = #{position}, </if>" +
            "</set>" +
            "where id = #{id}" +
            "</script>")
    int update(ModuleEntity module);

    @Select("select id, name, label, src, icon, description, position " +
            "from e_module")
    @Results(id = "ModuleEntity", value = {
            @Result(column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "label", property = "label"),
            @Result(column = "src", property = "src"),
            @Result(column = "icon", property = "icon"),
            @Result(column = "description", property = "description"),
            @Result(column = "position", property = "position"),
    })
    List<ModuleEntity> queryAll();
}
